<%--
  Created by IntelliJ IDEA.
  User: dylan-pc
  Date: 2017/8/16
  Time: 13:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>注册</title>
    <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/lib/jquery.js"></script>
    <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/jquery.validate.min.js"></script>
    <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/localization/messages_zh.js"></script>

    <script>
        /* $(document).ready(function () {

         //验证表单
         $("regForm").validate();

         //提交
         $("#regSubmit").click(function () {
         $("regForm").validate();
         alert("注册成功！");
         });
         });*/

        $.validator.setDefaults({
            regSubmit: function () {
                alert("提交事件!");
            }
        });

        $(function(){
            $('#regSubmit').click(function(){
                //alert(123);
                if($("#regForm").validate()){
                    alert("注册成功！");
                }
            })
        });


        $().ready(function () {
            $.validator.addMethod('notEqual', function (value, element) {
                //console.log("userPassword1:" + $("#userPassword").val());
                //console.log("userPassword2:" + value);

                var returnVal = false;
                if ($("#userPassword").val() == value) {
                    returnVal = true;
                }
                return returnVal;
            }, "两次密码输入不一致，请重新输入");

            $("#regForm").validate();
        });




    </script>

    <style>
        .error {
            color: red;
        }
    </style>
</head>
<body>
<h2>会员注册</h2>

<form id="regForm" action="" method="post">
    <table>
        <tr>
            <td><label for="userName">用户名：</label></td>
            <td><input type="text" id="userName" name="userName" maxlength="20" required/></td>
        </tr>

        <tr>
            <td><label for="userPassword">密码：</label></td>
            <td><input type="password" id="userPassword" name="userPassword" maxlength="20" required/></td>
        </tr>

        <tr>
            <td><label for="userPassword2">确认密码：</label></td>
            <td><input type="password" id="userPassword2" name="userPassword2" maxlength="20" required
                       class="notEqual"/></td>
        </tr>


        <tr>
            <td><label for="userMailAddr">邮箱：</label></td>
            <td><input type="text" id="userMailAddr" name="userMailAddr" class="email" required/></td>
        </tr>

        <tr>
            <td>
                <input id="regSubmit" name="regSubmit" type="submit" value="提交">
            </td>
        </tr>


    </table>

</form>
</body>
</html>
